package com.dios.mirage.navigation;

import java.io.InputStream;

import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import net.rim.device.api.ui.FontManager;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.decor.BackgroundFactory;

import com.dios.mirage.navigation.popup.NavigationPopup;

public abstract class Navigation extends LabelField {

	protected NavigationPopup popup;
	public final static String fontPath = "/font/Gotham-Bold.woff";
	
	public Navigation(String label) {
		super(label,Field.FOCUSABLE|Field.FIELD_VCENTER);
		init();
		createGUI();
	}

	public void init() {
		setBackground(BackgroundFactory.createSolidBackground(Color.BLACK));
		InputStream stream = getClass().getResourceAsStream(fontPath);
		setFont(loadCustomFonts(stream, Font.BOLD, 30));
		setMargin(10, 0, 0, 25);
	}

	protected void layout(int width, int height) {
		super.layout(width, height);
	}

	public static Font loadCustomFonts(InputStream stream, int fontStyle,
			int fontSize) {
		String fontname = "Gotham-Bold";
		try {
			if (FontManager.getInstance().load(stream, fontname,
					FontManager.APPLICATION_FONT) == FontManager.SUCCESS) {
				FontFamily family;
				family = FontFamily.forName(fontname);
				Font myFont = family.getFont(fontStyle, fontSize);
				return myFont;
			} else {
				FontFamily family;
				family = FontFamily.forName(fontname);
				Font myFont = family.getFont(fontStyle, fontSize);
				return myFont;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	protected abstract void createGUI();

	protected boolean navigationClick(int status, int time) {
		UiApplication.getUiApplication().pushScreen(popup);
		return true;
	}

	protected void paint(Graphics g) {
		g.setColor(Color.WHITE);
		super.paint(g);
	}
	

}
